package cn.webrx;

import java.util.*;

public class HashMap2 {
    public static void main(String[] args) {
        HashMap<String,User> hm = new HashMap<>();
        hm.put("s1",new User(22,"李四",20));
        hm.put("s2",new User(13,"李四",20));
        hm.put("s3",new User(15,"李四",20));
        hm.putIfAbsent("s4",new User(16,"李四",20));

        //遍历
        Set<String> ks = hm.keySet();
        for(String k : ks){
            System.out.println(k);
            System.out.println(hm.get(k));
        }

        //遍历值
        Collection<User> cs =  hm.values();
        for(User u : cs){
            System.out.println(u);
        }

        Iterator<Map.Entry<String, User>> iterator = hm.entrySet().iterator();
        while(iterator.hasNext()){
            Map.Entry<String,User> e = iterator.next();
            System.out.println(e);
            System.out.println(e.getKey());
            System.out.println(e.getValue());
        }


    }
}
